class ApiResponse<T> {
  final int? code;
  final String? message;
  final T? data;

  ApiResponse({this.code, this.message, this.data});

  factory ApiResponse.fromJson(
    Map<String, dynamic> json,
    T Function(dynamic json)? fromJsonT,
  ) {
    return ApiResponse(
      code: json['code'] is int ? json['code'] : null,
      message: json['message']?.toString(), // 可能为 null
      data:
          fromJsonT != null && json.containsKey('data') && json['data'] != null
              ? fromJsonT(json['data'])
              : null,
    );
  }
}
